package com.xx.ems.model;

import java.util.Date;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import com.xx.ems.util.impl.ObjectTransformImpl;

/**
 * @author xxx
 * @date 2014-2-25
 * @version 1.0
 * 描述: 设备表
 */
@Entity
public class Equipments {
	/**
	 * 描述：主键
	 */
	private Integer eid;
	/**
	 * 描述：输入的设备数量
	 */
	private int enternum;
	/**
	 * 描述：设备编号
	 */
	private String enumber;
	/**
	 * 描述：设备图片
	 */
	private String equipment_img;
	/**
	 * 描述：设备二维码图片
	 */
	private String qrcode_img;
	/**
	 * 描述：设备名称
	 */
	private String ename;
	/**
	 * 描述：设备价格
	 */
	private Double eprice;
	/**
	 * 描述：用户表关联对象 (责任人)
	 */
	private Users duty;
	/**
	 * 描述：用户表关联外键
	 */
	private Integer fk_duty;
	/**
	 * 描述：设备类型表关联对象 (设备类型)
	 */
	private Etypes type;
	/**
	 * 描述：设备类型表关联外键
	 */
	private Integer fk_type;
	/**
	 * 描述：设备型号
	 */
	private String emodel;
	/**
	 * 描述：设备状态表关联对象 (设备现状)
	 */
	private Estatus status;
	/**
	 * 描述：设备状态表关联外键
	 */
	private String fk_status;
	/**
	 * 描述：设备来源表关联对象 (设备来源)
	 */
	private Esource source;
	/**
	 * 描述：设备来源表关联外键
	 */
	private String fk_source;
	/**
	 * 描述：入库时间
	 */
	private Date in_time;
	/**
	 * 描述：厂家
	 */
	private String manufacturers;
	/**
	 * 描述：SN码
	 */
	private String sn_number;
	/**
	 * 描述：出厂日期
	 */
	private Date produced_date;
	/**
	 * 描述：设备年限
	 */
	private Integer deadline;
	/**
	 * 描述：购买时间
	 */
	private Date buy_time;
	/**
	 * 描述：供应商表关联对象 (供应商)
	 */
	private Providers provider;
	/**
	 * 描述：供应商表关联外键
	 */
	private String fk_provider;
	/**
	 * 描述：放置点
	 */
	private String storage;
	/**
	 * 描述：部门表关联对象 (部门)
	 */
	private Departments departments;
	/**
	 * 描述：部门表关联外键
	 */
	private String fk_did;
	/**
	 * 描述：审核状态 (0：未审核 , 1：审核成功 , 2：审核失败)
	 */
	private Integer approve_status;
	/**
	 * 描述：备注
	 */
	private String comment;
	/**
	 * 描述：附件表关联对象
	 */
	private Set<Accessory> accessory = new HashSet<Accessory>();
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="eid",unique=true,nullable=false)
	public Integer getEid() {
		return eid;
	}
	public void setEid(Integer eid) {
		this.eid = eid;
	}
	@Column(insertable=false,updatable=false)
	public int getEnternum() {
		return enternum;
	}
	public void setEnternum(int enternum) {
		this.enternum = enternum;
	}
	@Column(name="enumber",length=20,nullable=false)
	public String getEnumber() {
		return enumber;
	}
	public void setEnumber(String enumber) {
		this.enumber = enumber;
	}
	@Column(name="equipment_img",length=100)
	public String getEquipment_img() {
		return equipment_img;
	}
	public void setEquipment_img(String equipment_img) {
		this.equipment_img = equipment_img;
	}
	@Column(name="qrcode_img",length=100)
	public String getQrcode_img() {
		return qrcode_img;
	}
	public void setQrcode_img(String qrcode_img) {
		this.qrcode_img = qrcode_img;
	}
	@Column(name="ename",length=255,nullable=false)
	public String getEname() {
		return ename;
	}
	public void setEname(String ename) {
		this.ename = ename;
	}
	@Column(name="eprice",nullable=false)
	public Double getEprice() {
		return eprice;
	}
	public void setEprice(Double eprice) {
		this.eprice = eprice;
	}
	@ManyToOne(targetEntity=Users.class)
	@JoinColumn(name="fk_duty",insertable=false,updatable=false)
	public Users getDuty() {
		return duty;
	}
	public void setDuty(Users duty) {
		this.duty = duty;
	}
	@Column(name="fk_duty")
	public Integer getFk_duty() {
		return fk_duty;
	}
	public void setFk_duty(Integer fk_duty) {
		this.fk_duty = fk_duty;
	}
	@ManyToOne(targetEntity=Etypes.class)
	@JoinColumn(name="fk_type",insertable=false,updatable=false)
	public Etypes getType() {
		return type;
	}
	public void setType(Etypes type) {
		this.type = type;
	}
	@Column(name="fk_type")
	public Integer getFk_type() {
		return fk_type;
	}
	public void setFk_type(Integer fk_type) {
		this.fk_type = fk_type;
	}
	@Column(name="emodel",length=50)
	public String getEmodel() {
		return emodel;
	}
	public void setEmodel(String emodel) {
		this.emodel = emodel;
	}
	@ManyToOne(targetEntity=Estatus.class)
	@JoinColumn(name="fk_status",insertable=false,updatable=false)
	public Estatus getStatus() {
		return status;
	}
	public void setStatus(Estatus status) {
		this.status = status;
	}
	@Column(name="fk_status")
	public String getFk_status() {
		return fk_status;
	}
	public void setFk_status(String fk_status) {
		this.fk_status = fk_status;
	}
	@ManyToOne(targetEntity=Esource.class)
	@JoinColumn(name="fk_source",insertable=false,updatable=false)
	public Esource getSource() {
		return source;
	}
	public void setSource(Esource source) {
		this.source = source;
	}
	@Column(name="fk_source")
	public String getFk_source() {
		return fk_source;
	}
	public void setFk_source(String fk_source) {
		this.fk_source = fk_source;
	}
	@Column(name="in_time",nullable=false)
	public Date getIn_time() {
		return in_time;
	}
	public void setIn_time(Date in_time) {
		this.in_time = in_time;
	}
	@Column(name="manufacturers",length=100)
	public String getManufacturers() {
		return manufacturers;
	}
	public void setManufacturers(String manufacturers) {
		this.manufacturers = manufacturers;
	}
	@Column(name="sn_number",length=50)
	public String getSn_number() {
		return sn_number;
	}
	public void setSn_number(String sn_number) {
		this.sn_number = sn_number;
	}
	@Column(name="produced_date",nullable=false)
	public Date getProduced_date() {
		return produced_date;
	}
	public void setProduced_date(Date produced_date) {
		this.produced_date = produced_date;
	}
	@Column(name="deadline",nullable=false)
	public Integer getDeadline() {
		return deadline;
	}
	public void setDeadline(Integer deadline) {
		this.deadline = deadline;
	}
	@Column(name="buy_time",nullable=false)
	public Date getBuy_time() {
		return buy_time;
	}
	public void setBuy_time(Date buy_time) {
		this.buy_time = buy_time;
	}
	@ManyToOne(targetEntity=Providers.class)
	@JoinColumn(name="fk_provider",insertable=false,updatable=false)
	public Providers getProvider() {
		return provider;
	}
	public void setProvider(Providers provider) {
		this.provider = provider;
	}
	@Column(name="fk_provider")
	public String getFk_provider() {
		return fk_provider;
	}
	public void setFk_provider(String fk_provider) {
		this.fk_provider = fk_provider;
	}
	public String getStorage() {
		return storage;
	}
	@Column(name="storage",length=100)
	public void setStorage(String storage) {
		this.storage = storage;
	}
	@ManyToOne(targetEntity=Departments.class)
	@JoinColumn(name="fk_did",insertable=false,updatable=false)
	public Departments getDepartments() {
		return departments;
	}
	public void setDepartments(Departments departments) {
		this.departments = departments;
	}
	@Column(name="fk_did")
	public String getFk_did() {
		return fk_did;
	}
	public void setFk_did(String fk_did) {
		this.fk_did = fk_did;
	}
	@Column(name="approve_status",nullable=false)
	public Integer getApprove_status() {
		return approve_status;
	}
	public void setApprove_status(Integer approve_status) {
		this.approve_status = approve_status;
	}
	@Column(name="comment",length=255)
	public String getComment() {
		return comment;
	}
	public void setComment(String comment) {
		this.comment = comment;
	}
	@OneToMany(targetEntity=Accessory.class,mappedBy="equipments")
	public Set<Accessory> getAccessory() {
		return accessory;
	}
	public void setAccessory(Set<Accessory> accessory) {
		this.accessory = accessory;
	}
	/**
	 * 描述: 将实体的属性及相应的值转换成Map类型(为了方便转换成json格式后前台调用) 
	 * @return
	 * @date 2014-3-3
	 */
	public Map<String, Object> toHashMap() {
		Map<String, Object> map = new ObjectTransformImpl().javabeanToMap(this);
		map.put("duty", getDuty().getUsername());
		map.put("type", getType().getTname());
		map.put("status", getStatus().getSname());
		map.put("source", getSource().getSname());
		map.put("provider", getProvider().getPname());
		map.put("departments", getDepartments().getDname());
		return map;
	}
}